#include "customerrordialog.h"

#include<QTextCodec>
#include<QDebug>
#include<QScrollBar>

CustomErrorDialog::CustomErrorDialog(QWidget *parent) :
    QDialog(parent)
{
    //QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));

    v_layout = new QVBoxLayout;
    h_layout = new QHBoxLayout;
    this->setLayout(v_layout);

    label_icon = new QLabel();
    QPixmap pPixTip("/usr/share/cpktransform/images/tips_failure.png");
    label_icon->setPixmap(pPixTip.scaled(81,80,Qt::KeepAspectRatio));


    QString vertical_text = QString("QScrollBar:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,0,0,0%);"
                                    "margin:0px,0px,0px,0px;"
                                    "padding-top:9px;"
                                    "padding-bottom:9px;"
                                    "}"
                                    "QScrollBar::handle:vertical"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,25%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::handle:vertical:hover"
                                    "{"
                                    "width:8px;"
                                    "background:rgba(0,150,237,60%);"
                                    " border-radius:4px;"
                                    "min-height:20;"
                                    "}"
                                    "QScrollBar::add-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/down_normal.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_normal.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/down_pressed.png);"
                                    "subcontrol-position:bottom;"
                                    "}"
                                    "QScrollBar::sub-line:vertical:hover"
                                    "{"
                                    "height:9px;width:8px;"
                                    "border-image:url(/usr/share/cpktransform/images/up_pressed.png);"
                                    "subcontrol-position:top;"
                                    "}"
                                    "QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical"
                                    "{"
                                    "background:rgba(77,0,0,10%);"
                                    "border-radius:4px;"
                                    "}");
    textEdit_errorInfoDes = new QTextEdit();
    textEdit_errorInfoDes->setFixedHeight(150);
    textEdit_errorInfoDes->setFixedWidth(340);
    textEdit_errorInfoDes->setStyleSheet("QTextEdit{background-color:rgb(255,255,240);border-image:none; border:1px solid gray; border-radius:2px}");
    textEdit_errorInfoDes->verticalScrollBar()->setStyleSheet(vertical_text );
    textEdit_errorInfoDes->setReadOnly(true);

    btn_sure = new QPushButton();
    btn_sure->setText("确定");
    //    btn_sure->setStyleSheet(button_style);
    //    btn_sure->setStyleSheet("QPushButton{border:1px groove gray;border-radius:5px; font-family:'Microsoft YaHei'; font-size:16px;border-style: flat;};");
    btn_sure->setCursor(Qt::PointingHandCursor);
    connect(btn_sure,SIGNAL(clicked()), this, SLOT(accept()));
    QPalette palette = btn_sure->palette();
    palette.setColor(QPalette::Active,QPalette::ButtonText,QColor(240,250,250));
    btn_sure->setPalette(palette);

    v_layout->addLayout(h_layout);
    v_layout->setAlignment(h_layout, Qt::AlignCenter);
    v_layout->addWidget(btn_sure);
    v_layout->setAlignment(btn_sure, Qt::AlignRight);

    h_layout->addWidget(label_icon);
    h_layout->setAlignment(label_icon, Qt::AlignHCenter);
    h_layout->addWidget(textEdit_errorInfoDes);
    h_layout->setAlignment(textEdit_errorInfoDes, Qt::AlignHCenter);

}

void CustomErrorDialog::setErrorInfo(QString qstr_ErrorInfo)
{
    textEdit_errorInfoDes->setText(qstr_ErrorInfo);
}

void CustomErrorDialog::okClicked()
{
    qDebug() << "OK";
}
